<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="&amp;#x9664;&amp;#x4E86;&amp;#x5B57;&amp;#x7B26;&amp;#x4E32;&amp;#x3001;&amp;#x6570;&amp;#x5B57;&amp;#x3001;true&amp;#x3001;false&amp;#x3001;null &amp;#x548C; undefined &amp;#x4E4B;&amp;#x5916;&amp;#xFF0C;JavaScript &amp;#x4E2D;&amp;#x7684;&amp;#x503C;&amp;#x90FD;&amp;#x662F;&amp;#x5">
<meta property="og:type" content="article">
<meta property="og:title" content="js 的对象">
<meta property="og:url" content="https://hongqinma.github.io/2014/05/02/js-的对象/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="&amp;#x9664;&amp;#x4E86;&amp;#x5B57;&amp;#x7B26;&amp;#x4E32;&amp;#x3001;&amp;#x6570;&amp;#x5B57;&amp;#x3001;true&amp;#x3001;false&amp;#x3001;null &amp;#x548C; undefined &amp;#x4E4B;&amp;#x5916;&amp;#xFF0C;JavaScript &amp;#x4E2D;&amp;#x7684;&amp;#x503C;&amp;#x90FD;&amp;#x662F;&amp;#x5">
<meta property="og:updated_time" content="2016-11-09T11:31:34.444Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js 的对象">
<meta name="twitter:description" content="&amp;#x9664;&amp;#x4E86;&amp;#x5B57;&amp;#x7B26;&amp;#x4E32;&amp;#x3001;&amp;#x6570;&amp;#x5B57;&amp;#x3001;true&amp;#x3001;false&amp;#x3001;null &amp;#x548C; undefined &amp;#x4E4B;&amp;#x5916;&amp;#xFF0C;JavaScript &amp;#x4E2D;&amp;#x7684;&amp;#x503C;&amp;#x90FD;&amp;#x662F;&amp;#x5">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2014/05/02/js-的对象/"/>


  <title> js 的对象 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                js 的对象
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2014-05-02T20:14:53+08:00" content="2014-05-02">
              2014-05-02
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2014/05/02/js-的对象/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2014/05/02/js-的对象/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2014/05/02/js-的对象/" class="leancloud_visitors" data-flag-title="js 的对象">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">visitors </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
          <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#x9664;&#x4E86;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x6570;&#x5B57;&#x3001;true&#x3001;false&#x3001;null &#x548C; undefined &#x4E4B;&#x5916;&#xFF0C;JavaScript &#x4E2D;&#x7684;&#x503C;&#x90FD;&#x662F;&#x5BF9;&#x8C61;&#x3002;<br>&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF08;&#x5BF9;&#x8C61;&#xFF09;&#x662F;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;&#x5728; ECMAScript &#x4E2D;&#xFF0C;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x662F;&#x4E00;&#x79CD;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;<br>&#x7528;&#x4E8E;&#x5C06;&#x6570;&#x636E;&#x548C;&#x529F;&#x80FD;&#x7EC4;&#x7EC7;&#x5728;&#x4E00;&#x8D77;&#x3002;</p>
<p>&#x4ECE;&#x5B8F;&#x89C2;&#x7684;&#x89D2;&#x5EA6;&#x8BB2;&#xFF0C;&#x5BF9;&#x8C61;&#x662F;&#x5BF9;&#x5BA2;&#x89C2;&#x4E8B;&#x7269;&#x7684;&#x62BD;&#x8C61;&#xFF0C;<br>&#x4E8B;&#x7269;&#x7684;&#x7279;&#x5F81;&#x53EF;&#x4EE5;&#x7528;&#x5C5E;&#x6027;&#x8868;&#x793A;&#xFF0C;&#x4E8B;&#x7269;&#x7684;&#x884C;&#x4E3A;&#x53EF;&#x4EE5;&#x7528;&#x65B9;&#x6CD5;&#x8868;&#x793A;&#xFF1B;</p>
<p>&#x4ECE;&#x5FAE;&#x89C2;&#x7684;&#x89D2;&#x5EA6;&#x8BB2;&#xFF0C;&#x5BF9;&#x8C61;&#x5C31;&#x662F;&#x4E00;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x901A;&#x8FC7;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x5730;&#x5BF9;&#x53D8;&#x91CF;&#x548C;&#x51FD;&#x6570;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#x3002;</p>
<h2 id="&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;"><a href="#&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;" class="headerlink" title="&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;"></a>&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;</h2><p>JavaScript &#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;&#x6709;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;&#x76F4;&#x63A5;&#x91CF;&#xFF0C;new &#x5173;&#x952E;&#x5B57; &#x548C; Object.creat() &#x65B9;&#x6765;&#x521B;&#x5EFA;&#x3002;</p>
<h3 id="&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;"><a href="#&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;" class="headerlink" title="&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;"></a>&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;</h3><p>&#x5BF9;&#x8C61;&#x7684;&#x76F4;&#x63A5;&#x91CF;&#x5C31;&#x662F;&#x7531;&#x82E5;&#x5E72;&#x517C;&#x804C;&#x5BF9;&#x7EC4;&#x6210;&#x7684;&#x6620;&#x5C04;&#x8868;&#xFF0C; &#x952E;&#x548C;&#x503C;&#x4E4B;&#x95F4;&#x7528; &#x201C;:&#x201D; &#x5206;&#x9694;&#xFF0C;&#x952E;&#x503C;&#x5BF9;&#x4E4B;&#x95F4;&#x7528; &#x201C;,&#x201D; &#x5206;&#x9694;&#xFF0C;<br>&#x6574;&#x4E2A;&#x6620;&#x5C04;&#x8868;&#x7528;&#x4E00;&#x5BF9;&#x82B1;&#x62EC;&#x53F7;&#x5305;&#x88F9;&#xFF0C;&#x6BD4;&#x5982;&#x901A;&#x8FC7;&#x5B57;&#x9762;&#x91CF;&#x58F0;&#x660E;&#xFF08;&#x66F4;&#x52A0;&#x7B80;&#x4FBF;&#xFF09;<code>var obj= {};</code></p>
<h4 id="&#x952E;&#x503C;&#x5BF9;"><a href="#&#x952E;&#x503C;&#x5BF9;" class="headerlink" title="&#x952E;&#x503C;&#x5BF9;"></a>&#x952E;&#x503C;&#x5BF9;</h4><p>&#x952E;&#x503C;&#x5BF9;&#x5C31;&#x662F;&#x4E00;&#x79CD;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;&#xFF0C;&#x901A;&#x8FC7;&#x952E;&#x80FD;&#x591F;&#x65B9;&#x4FBF;&#x5730;&#x627E;&#x5230;&#x503C;</p>
<p>&#x952E;:&#x503C;    <code>key:value</code>    <code>k:v</code></p>
<h4 id="&#x4F8B;&#x5B50;&#xFF1A;"><a href="#&#x4F8B;&#x5B50;&#xFF1A;" class="headerlink" title="&#x4F8B;&#x5B50;&#xFF1A;"></a>&#x4F8B;&#x5B50;&#xFF1A;</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> emptyObj = {};</div><div class="line"><span class="keyword">var</span> pointObj = {<span class="attr">x</span>:<span class="number">0</span>, <span class="attr">y</span>:<span class="number">0</span>};</div><div class="line"><span class="keyword">var</span> pointObj2 = {<span class="attr">x</span>: pointObj.x, <span class="attr">y</span>: pointObj.y};</div><div class="line"><span class="keyword">var</span> books = {</div><div class="line">  <span class="string">&quot;main title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,   <span class="comment">// &#x5C5E;&#x6027;&#x540D;&#x4E2D;&#x6709;&#x7A7A;&#x683C;&#x65F6;&#xFF0C;&#x5FC5;&#x987B;&#x7528;&#x5B57;&#x7B26;&#x4E32;</span></div><div class="line">  <span class="string">&apos;sub-title&apos;</span>: <span class="string">&quot;The Definitive Guide&quot;</span>,   <span class="comment">// &#x5C5E;&#x6027;&#x540D;&#x4E2D;&#x6709;&#x8FDE;&#x5B57;&#x7B26;&#xFF0C;&#x5FC5;&#x987B;&#x7528;&#x5B57;&#x7B26;&#x4E32;</span></div><div class="line">  <span class="string">&quot;for&quot;</span>: <span class="string">&quot;all audiences&quot;</span>,   <span class="comment">// &quot;for&quot; &#x662F;&#x4FDD;&#x7559;&#x5B57;&#xFF0C;&#x5FC5;&#x987B;&#x7528;&#x5F15;&#x53F7;</span></div><div class="line">  author: {     <span class="comment">// &#x8FD9;&#x91CC;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x6CA1;&#x6709;&#x5F15;&#x53F7;</span></div><div class="line">    firstname: <span class="string">&quot;Hiraku&quot;</span>,</div><div class="line">    <span class="attr">surname</span>: <span class="string">&quot;Hongqin&quot;</span></div><div class="line">  }</div><div class="line">};</div></pre></td></tr></table></figure>
<p>&#x5BF9;&#x8C61;&#x7684;&#x5B57;&#x9762;&#x91CF;&#x662F;&#x4E00;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x8FD9;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x6BCF;&#x6B21;&#x8FD0;&#x7B97;&#x90FD;&#x521B;&#x5EFA;&#x5E76;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#x3002;<br>&#x6BCF;&#x6B21;&#x8BA1;&#x7B97;&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E5F;&#x4F1A;&#x8BA1;&#x7B97;&#x5B83;&#x7684;&#x6BCF;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x3002;<br>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x4E00;&#x4E2A;&#x91CD;&#x590D;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x5FAA;&#x73AF;&#x4F53;&#x5185;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;&#xFF0C;<br>&#x5B83;&#x5C06;&#x521B;&#x5EFA;&#x5F88;&#x591A;&#x65B0;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x4E14;&#x6BCF;&#x6B21;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x53EF;&#x6709;&#x53EF;&#x80FD;&#x4E0D;&#x540C;&#x3002;</p>
<h2 id="&#x901A;&#x8FC7;-new-&#x5173;&#x952E;&#x5B57;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;"><a href="#&#x901A;&#x8FC7;-new-&#x5173;&#x952E;&#x5B57;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;" class="headerlink" title="&#x901A;&#x8FC7; new &#x5173;&#x952E;&#x5B57;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;"></a>&#x901A;&#x8FC7; new &#x5173;&#x952E;&#x5B57;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</h2><p>new &#x8FD0;&#x7B97;&#x7B26;&#x521B;&#x5EFA;&#x5E76;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#x3002;n&#x5173;&#x952E;&#x5B57; new &#x540E;&#x9762;&#x8DDF;&#x968F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x6784;&#x9020;&#x51FD;&#x6570;&#x58F0;&#x660E;&#xFF08;&#x66F4;&#x52A0;&#x901A;&#x7528;&#xFF09;var obj= new Object(); // &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#xFF0C;&#x548C; {} &#x4E00;&#x6837;</p>
<p>&#x5BF9;&#x8C61;&#x5177;&#x6709;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;</p>
<ul>
<li>&#x5C5E;&#x6027; &#x7528;&#x6765;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#x7684;&#x7279;&#x5F81; &#x4E00;&#x822C;&#x662F;&#x540D;&#x8BCD; &#x5BF9;&#x5E94;&#x53D8;&#x91CF;</li>
<li>&#x65B9;&#x6CD5; &#x7528;&#x6765;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#x7684;&#x884C;&#x4E3A; &#x4E00;&#x822C;&#x662F;&#x52A8;&#x8BCD; &#x5BF9;&#x5E94;&#x51FD;&#x6570;</li>
</ul>
<h2 id="&#x539F;&#x578B;&#x521D;&#x8BC6;"><a href="#&#x539F;&#x578B;&#x521D;&#x8BC6;" class="headerlink" title="&#x539F;&#x578B;&#x521D;&#x8BC6;"></a>&#x539F;&#x578B;&#x521D;&#x8BC6;</h2><p>&#x9664;&#x4E86; null &#x4EE5;&#x5916;&#x7684;&#x6BCF;&#x4E00;&#x4E2A; JavaScript &#x5BF9;&#x8C61;&#x90FD;&#x548C; <code>&#x539F;&#x578B;</code> &#x76F8;&#x5173;&#x8054;&#x3002;<br>&#x6240;&#x6709;&#x901A;&#x8FC7;&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x91CF;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x5BF9;&#x5177;&#x6709;&#x540C;&#x4E00;&#x4E2A;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;<br>&#x53EF;&#x901A;&#x8FC7; Object.prototype &#x83B7;&#x5F97;&#x5BF9;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#x3002;<br>&#x901A;&#x8FC7; new &#x5173;&#x952E;&#x5B57;&#x548C;&#x6784;&#x9020;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x5C31;&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684; prototype &#x5C5E;&#x6027;&#x7684;&#x503C;&#x3002;<br>&#x56E0;&#x6B64;&#xFF0C;&#x548C;&#x4F7F;&#x7528; {} &#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x4E00;&#x6837;&#xFF0C;&#x901A;&#x8FC7; new Object() &#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x4E5F;&#x7EE7;&#x627F;&#x81EA; Object.prototype&#x3002;</p>
<p>&#x6CA1;&#x6709;&#x539F;&#x578B;&#x7684;&#x5BF9;&#x8C61;&#x6709; Object.prototype&#xFF0C;&#x5B83;&#x4E0D;&#x7EE7;&#x627F;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#x3002;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x90FD;&#x662F;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#xFF0C;&#x90FD;&#x6709;&#x539F;&#x578B;&#x3002;<br>&#x6240;&#x6709;&#x7684;&#x5185;&#x7F6E;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6BD4;&#x5982;&#xFF1A;Array(), Date() &#x90FD;&#x5177;&#x6709;&#x4E00;&#x4E2A;&#x7EE7;&#x627F;&#x81EA; Object.prototype &#x7684;&#x539F;&#x578B;&#x3002;</p>
<h2 id="Object-create"><a href="#Object-create" class="headerlink" title="Object.create()"></a>Object.create()</h2><p>ECMAScript 5 &#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; Object.create() &#x65B9;&#x6CD5;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x3002;&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;<br>&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x53EF;&#x9009;&#xFF0C;&#x7528;&#x4E8E;&#x5BF9;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x8BE6;&#x7EC6;&#x63CF;&#x8FF0;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// o1 &#x7EE7;&#x627F;&#x4E86;&#x5C5E;&#x6027; x &#x548C; y</span></div><div class="line"><span class="keyword">var</span> o1 = <span class="built_in">Object</span>.create({<span class="attr">x</span>:<span class="number">1</span>, <span class="attr">y</span>:<span class="number">1</span>});  </div><div class="line"><span class="comment">// o2 &#x4E0D;&#x7EE7;&#x627F;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x6CA1;&#x6709;&#x539F;&#x578B;&#xFF0C;&#x4E0D;&#x80FD;&#x548C; + &#x8FD0;&#x7B97;&#x7B26;&#x4E00;&#x8D77;&#x5DE5;&#x4F5C;</span></div><div class="line"><span class="keyword">var</span> o2 = <span class="built_in">Object</span>.create(<span class="literal">null</span>);</div><div class="line"><span class="comment">// o3 &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x7A7A;&#x5BF9;&#x8C61;</span></div><div class="line"><span class="keyword">var</span> o3 = <span class="built_in">Object</span>.create(<span class="built_in">Object</span>.prototype);</div></pre></td></tr></table></figure>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EFB;&#x610F;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x65B0;&#x5BF9;&#x8C61;&#xFF0C;&#x5373;&#x53EF;&#x4EE5;&#x4F7F;&#x4EFB;&#x610F;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x3002;</p>
<p>&#x4F8B;&#x5B50;&#xFF1A; &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7EE7;&#x627F;&#x81EA;&#x539F;&#x578B;&#x5BF9;&#x8C61; p &#x7684;&#x5C5E;&#x6027;&#x7684;&#x65B0;&#x5BF9;&#x8C61;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">inherit</span>(<span class="params">p</span>)</span>{</div><div class="line">  <span class="keyword">if</span> (p == <span class="literal">null</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();            <span class="comment">// p &#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span></div><div class="line">  <span class="keyword">if</span> (<span class="built_in">Object</span>.create) <span class="keyword">return</span> <span class="built_in">Object</span>.create(p);  <span class="comment">// &#x5982;&#x679C;&#x5B58;&#x5728; Object.create&#xFF0C;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5B83;&#x6765;&#x521B;&#x5EFA;</span></div><div class="line">  <span class="keyword">var</span> t = <span class="keyword">typeof</span> p;  <span class="comment">// &#x5426;&#x5219;&#x8FDB;&#x4E00;&#x6B65;&#x68C0;&#x6D4B;</span></div><div class="line">  <span class="keyword">if</span> (t !== <span class="string">&quot;object&quot;</span> &amp;&amp; t !== <span class="string">&quot;function&quot;</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();</div><div class="line">  <span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params"></span>) </span>{}; <span class="comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x6784;&#x9020;&#x51FD;&#x6570;</span></div><div class="line">  f.prototype = p; <span class="comment">// &#x5C06;&#x5176;&#x539F;&#x578B;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x4E3A; p</span></div><div class="line">  <span class="keyword">return</span> <span class="keyword">new</span> f(); <span class="comment">// &#x4F7F;&#x7528; f() &#x521B;&#x5EFA; p &#x7684;&#x7EE7;&#x627F;&#x5BF9;&#x8C61;</span></div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x67E5;&#x8BE2;&#x548C;&#x8BBE;&#x7F6E;"><a href="#&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x67E5;&#x8BE2;&#x548C;&#x8BBE;&#x7F6E;" class="headerlink" title="&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x67E5;&#x8BE2;&#x548C;&#x8BBE;&#x7F6E;"></a>&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x67E5;&#x8BE2;&#x548C;&#x8BBE;&#x7F6E;</h2><h3 id="&#x5C5E;&#x6027;"><a href="#&#x5C5E;&#x6027;" class="headerlink" title="&#x5C5E;&#x6027;"></a>&#x5C5E;&#x6027;</h3><ul>
<li>&#x5C5E;&#x6027;&#x7684;&#x5B9A;&#x4E49; <ul>
<li>&#x5BF9;&#x8C61;.&#x5C5E;&#x6027;&#x540D; = &#x503C;&#xFF1B;</li>
<li>&#x5BF9;&#x8C61;[&#x201C;&#x5C5E;&#x6027;&#x540D;&#x201D;] = &#x503C;;</li>
</ul>
</li>
<li>&#x5C5E;&#x6027;&#x7684;&#x8C03;&#x7528; <ul>
<li>&#x5BF9;&#x8C61;.&#x5C5E;&#x6027;&#x540D;;</li>
<li>&#x5BF9;&#x8C61;[&#x201C;&#x5C5E;&#x6027;&#x540D;&#x201D;];</li>
</ul>
</li>
</ul>
<h3 id="&#x65B9;&#x6CD5;"><a href="#&#x65B9;&#x6CD5;" class="headerlink" title="&#x65B9;&#x6CD5;"></a>&#x65B9;&#x6CD5;</h3><ul>
<li>&#x65B9;&#x6CD5;&#x7684;&#x5B9A;&#x4E49; <ul>
<li>&#x5BF9;&#x8C61;.&#x65B9;&#x6CD5;&#x540D; = function() { //&#x51FD;&#x6570;&#x4F53; };</li>
<li>&#x5BF9;&#x8C61;[&#x201C;&#x65B9;&#x6CD5;&#x540D;&#x201D;] = function() { //&#x51FD;&#x6570;&#x4F53; };</li>
</ul>
</li>
<li>&#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528; <ul>
<li>&#x5BF9;&#x8C61;.&#x65B9;&#x6CD5;&#x540D;();</li>
<li>&#x5BF9;&#x8C61;[&#x201C;&#x65B9;&#x6CD5;&#x540D;&#x201D;];</li>
</ul>
</li>
</ul>
<h3 id="&#x4F5C;&#x4E3A;&#x5173;&#x8054;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;"><a href="#&#x4F5C;&#x4E3A;&#x5173;&#x8054;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;" class="headerlink" title="&#x4F5C;&#x4E3A;&#x5173;&#x8054;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;"></a>&#x4F5C;&#x4E3A;&#x5173;&#x8054;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;</h3><p>&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E8C;&#x79CD;&#x8BBE;&#x7F6E;&#x548C;&#x8BBF;&#x95EE;&#x7528;&#x4E86; &#x201C;[]&#x201D;&#xFF0C;&#x53EA;&#x662F;&#x5229;&#x7528;&#x7684;&#x4E0D;&#x662F;&#x7D22;&#x5F15;&#x8BBF;&#x95EE;&#xFF0C;&#x800C;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x3002;<br>&#x8FD9;&#x79CD;&#x6570;&#x636E;&#x5C31;&#x662F;&#x5173;&#x8054;&#x6570;&#x7EC4;&#xFF0C;&#x4E5F;&#x53EB;&#x6563;&#x5217;&#x3001;&#x6620;&#x5C04;&#x6216;&#x8005;&#x5B57;&#x5178;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x901A;&#x8FC7; [] &#x6765;&#x8BBF;&#x95EE;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x5728;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x662F;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x548C;&#x4FEE;&#x6539;&#x6216;&#x8005;&#x521B;&#x5EFA;&#x5B83;&#x4EEC;&#x3002;</p>
<h3 id="&#x7EE7;&#x627F;"><a href="#&#x7EE7;&#x627F;" class="headerlink" title="&#x7EE7;&#x627F;"></a>&#x7EE7;&#x627F;</h3><p>&#x5BF9;&#x8C61;&#x5177;&#x6709;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#xFF08;own property&#xFF09;&#xFF0C;&#x4E5F;&#x6709;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x662F;&#x4ECE;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E0A;&#x7EE7;&#x627F;&#x6765;&#x7684;</p>
<p>&#x8FD8;&#x662F;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">inherit</span>(<span class="params">p</span>)</span>{</div><div class="line">  <span class="keyword">if</span> (p == <span class="literal">null</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();            <span class="comment">// p &#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span></div><div class="line">  <span class="keyword">if</span> (<span class="built_in">Object</span>.create) <span class="keyword">return</span> <span class="built_in">Object</span>.create(p);  <span class="comment">// &#x5982;&#x679C;&#x5B58;&#x5728; Object.create&#xFF0C;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5B83;&#x6765;&#x521B;&#x5EFA;</span></div><div class="line">  <span class="keyword">var</span> t = <span class="keyword">typeof</span> p;  <span class="comment">// &#x5426;&#x5219;&#x8FDB;&#x4E00;&#x6B65;&#x68C0;&#x6D4B;</span></div><div class="line">  <span class="keyword">if</span> (t !== <span class="string">&quot;object&quot;</span> &amp;&amp; t !== <span class="string">&quot;function&quot;</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();</div><div class="line">  <span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params"></span>) </span>{}; <span class="comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x6784;&#x9020;&#x51FD;&#x6570;</span></div><div class="line">  f.prototype = p; <span class="comment">// &#x5C06;&#x5176;&#x539F;&#x578B;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x4E3A; p</span></div><div class="line">  <span class="keyword">return</span> <span class="keyword">new</span> f(); <span class="comment">// &#x4F7F;&#x7528; f() &#x521B;&#x5EFA; p &#x7684;&#x7EE7;&#x627F;&#x5BF9;&#x8C61;</span></div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">var</span> o = {};</div><div class="line">o.x = <span class="number">1</span>;</div><div class="line"><span class="keyword">var</span> p = inherit(o);  <span class="comment">// p &#x7EE7;&#x627F;&#x81EA;&#x5BF9;&#x8C61; o &#x548C; Object.prototype</span></div><div class="line">p.y = <span class="number">2</span>;</div><div class="line"><span class="keyword">var</span> q = inherit(p);  <span class="comment">// q &#x7EE7;&#x627F;&#x81EA;&#x5BF9;&#x8C61; p&#x3001; o &#x548C; Object.prototype</span></div><div class="line">q.z = <span class="number">3</span>;</div><div class="line"><span class="keyword">var</span> s = q.toString();</div><div class="line"><span class="built_in">console</span>.log(s);  <span class="comment">// &quot;[object object]&quot;</span></div><div class="line"><span class="built_in">console</span>.log(q.x + q.y + q.z); <span class="comment">// 6 &#x5C5E;&#x6027; x &#x548C; y &#x5206;&#x522B;&#x7EE7;&#x627F;&#x81EA; o &#x548C; p</span></div></pre></td></tr></table></figure>
<h3 id="&#x5C5E;&#x6027;&#x8BBF;&#x95EE;&#x9519;&#x8BEF;"><a href="#&#x5C5E;&#x6027;&#x8BBF;&#x95EE;&#x9519;&#x8BEF;" class="headerlink" title="&#x5C5E;&#x6027;&#x8BBF;&#x95EE;&#x9519;&#x8BEF;"></a>&#x5C5E;&#x6027;&#x8BBF;&#x95EE;&#x9519;&#x8BEF;</h3><ul>
<li>JavaScript &#x4E2D;&#xFF0C;&#x5C5E;&#x6027;&#x8BBF;&#x95EE;&#x65F6;&#xFF0C;&#x5E76;&#x4E0D;&#x603B;&#x662F;&#x4F1A;&#x8BDD;&#x6216;&#x8005;&#x8BBE;&#x7F6E;&#x3002;</li>
<li>&#x5728;&#x67E5;&#x8BE2;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#x65F6;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x800C;&#x8FD4;&#x56DE; undefined&#x3002;</li>
<li>&#x5185;&#x7F6E;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x539F;&#x578B;&#x662F;&#x53EA;&#x8BFB;&#x7684;&#x3002;</li>
</ul>
<h2 id="&#x5220;&#x9664;&#x5C5E;&#x6027;"><a href="#&#x5220;&#x9664;&#x5C5E;&#x6027;" class="headerlink" title="&#x5220;&#x9664;&#x5C5E;&#x6027;"></a>&#x5220;&#x9664;&#x5C5E;&#x6027;</h2><p>delete &#x8FD0;&#x7B97;&#x7B26;&#x53EF;&#x4EE5;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002;delete &#x53EA;&#x662F;&#x65AD;&#x5F00;&#x5C5E;&#x6027;&#x548C;&#x5BBF;&#x4E3B;&#x5BF9;&#x8C61;&#x7684;&#x8054;&#x7CFB;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x64CD;&#x4F5C;&#x5C5E;&#x6027;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<p>delete &#x53EA;&#x80FD;&#x5220;&#x9664;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#xFF0C;&#x4E0D;&#x80FD;&#x5220;&#x9664;&#x7EE7;&#x627F;&#x5C5E;&#x6027;&#x3002;</p>
<p>delete &#x4E0D;&#x80FD;&#x5220;&#x9664;&#x53EF;&#x914D;&#x7F6E;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x5728;&#x975E;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;&#x5220;&#x9664;&#x5168;&#x5C40;&#x72EC;&#x4EAB;&#x7684;&#x53EF;&#x914D;&#x7F6E;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x5BF9;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#xFF0C;<br>&#x76F4;&#x63A5;&#x5728; delete &#x64CD;&#x4F5C;&#x7B26;&#x540E;&#x8DDF;&#x8981;&#x5220;&#x9664;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x5373;&#x53EF;&#x3002;</p>
<p>&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;delete x; &#x62A5;&#x9519;&#xFF0C; delete this.x; &#x6B63;&#x5E38;&#x8FD0;&#x884C;</p>
<h2 id="&#x5C5E;&#x6027;&#x68C0;&#x6D4B;"><a href="#&#x5C5E;&#x6027;&#x68C0;&#x6D4B;" class="headerlink" title="&#x5C5E;&#x6027;&#x68C0;&#x6D4B;"></a>&#x5C5E;&#x6027;&#x68C0;&#x6D4B;</h2><p>&#x901A;&#x8FC7; in &#x8FD0;&#x7B97;&#x7B26;&#x3001;hasOwnProperty()&#x3001;propertyIsEnumerable() &#x65B9;&#x6CD5;&#xFF1B;</p>
<ul>
<li>in &#x8FD0;&#x7B97;&#x7B26;  </li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> o = {<span class="attr">x</span>: <span class="number">1</span>};</div><div class="line"><span class="string">&quot;x&quot;</span> <span class="keyword">in</span> o;  <span class="comment">// true &quot;x&quot; &#x662F; o &#x7684;&#x5C5E;&#x6027;</span></div></pre></td></tr></table></figure>
<ul>
<li>hasOwnProperty() &#x65B9;&#x6CD5;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> o = {<span class="attr">x</span>: <span class="number">1</span>};</div><div class="line">o.hasOwnProperty(x);  <span class="comment">// true &quot;x&quot; &#x662F; o &#x7684;&#x81EA;&#x6709;&#x5C5E;&#x6027;</span></div><div class="line">o.hasOwnProperty(<span class="keyword">constructor</span>);  // false <span class="keyword">constructor</span> &#x662F;&#x539F;&#x578B;&#x4E2D;&#x7684;&#x5C5E;&#x6027;</div></pre></td></tr></table></figure>
<ul>
<li>propertyIsEnumerable() &#x65B9;&#x6CD5;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">inherit</span>(<span class="params">p</span>)</span>{</div><div class="line">  <span class="keyword">if</span> (p == <span class="literal">null</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();            <span class="comment">// p &#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span></div><div class="line">  <span class="keyword">if</span> (<span class="built_in">Object</span>.create) <span class="keyword">return</span> <span class="built_in">Object</span>.create(p);  <span class="comment">// &#x5982;&#x679C;&#x5B58;&#x5728; Object.create&#xFF0C;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5B83;&#x6765;&#x521B;&#x5EFA;</span></div><div class="line">  <span class="keyword">var</span> t = <span class="keyword">typeof</span> p;  <span class="comment">// &#x5426;&#x5219;&#x8FDB;&#x4E00;&#x6B65;&#x68C0;&#x6D4B;</span></div><div class="line">  <span class="keyword">if</span> (t !== <span class="string">&quot;object&quot;</span> &amp;&amp; t !== <span class="string">&quot;function&quot;</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();</div><div class="line">  <span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params"></span>) </span>{}; <span class="comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x6784;&#x9020;&#x51FD;&#x6570;</span></div><div class="line">  f.prototype = p; <span class="comment">// &#x5C06;&#x5176;&#x539F;&#x578B;&#x5C5E;&#x6027;&#x8BBE;&#x7F6E;&#x4E3A; p</span></div><div class="line">  <span class="keyword">return</span> <span class="keyword">new</span> f(); <span class="comment">// &#x4F7F;&#x7528; f() &#x521B;&#x5EFA; p &#x7684;&#x7EE7;&#x627F;&#x5BF9;&#x8C61;</span></div><div class="line">}</div><div class="line"><span class="keyword">var</span> o = interit({<span class="attr">x</span>: <span class="number">1</span>});</div><div class="line">o.y = <span class="number">1</span>;  </div><div class="line">o.propertyIsEnumerable(<span class="string">&quot;x&quot;</span>); <span class="comment">// false &quot;x&quot; &#x5C5E;&#x6027;&#x662F;&#x7EE7;&#x627F;&#x7684;&#xFF0C;&#x4E0D;&#x80FD;&#x88AB;&#x679A;&#x4E3E;</span></div><div class="line">o.propertyIsEnumerable(<span class="string">&quot;y&quot;</span>); <span class="comment">// true</span></div></pre></td></tr></table></figure>
<p>&#x9664;&#x4E86; in &#x4EE5;&#x5916;&#xFF0C; &#x53E6;&#x4E00;&#x79CD;&#x7B80;&#x5355;&#x7684;&#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x662F;&#x5426;&#x662F; &#x201C;undefined&#x201D; &#x4F7F;&#x7528; &#x201C;!==&#x201D;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> o = {<span class="attr">x</span>: <span class="number">1</span>};</div><div class="line">o.x !== <span class="literal">undefined</span>;   <span class="comment">// true</span></div><div class="line">o.y !== <span class="literal">undefined</span>;   <span class="comment">// false;</span></div><div class="line">o.toString !== <span class="literal">undefined</span>; <span class="comment">// true</span></div></pre></td></tr></table></figure>
<p>&#x4F46; in &#x53EF;&#x4EE5;&#x533A;&#x5206;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x5B58;&#x5728;&#x4F46;&#x503C;&#x4E3A; undefined &#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> o = {<span class="attr">x</span>: <span class="literal">undefined</span>};</div><div class="line">o.x !== <span class="literal">undefined</span>;   <span class="comment">// false  &#x5C5E;&#x6027;&#x5B58;&#x5728;&#xFF0C;&#x4F46;&#x662F;&#x503C;&#x4E3A; undefined</span></div><div class="line">o.y !== <span class="literal">undefined</span>;   <span class="comment">// false  &#x5C5E;&#x6027;&#x4E0D;&#x5B58;&#x5728;</span></div><div class="line"><span class="string">&quot;x&quot;</span> <span class="keyword">in</span> o; <span class="comment">// true &#x5C5E;&#x6027;&#x5B58;&#x5728;</span></div><div class="line"><span class="string">&quot;y&quot;</span> <span class="keyword">in</span> o; <span class="comment">// false &#x5C5E;&#x6027;&#x4E0D;&#x5B58;&#x5728;</span></div><div class="line"><span class="keyword">delete</span> o.x;  <span class="comment">// &#x5220;&#x9664;&#x4E86;&#x5C5E;&#x6027; x</span></div><div class="line"><span class="string">&quot;x&quot;</span> <span class="keyword">in</span> o; <span class="comment">// false &#x5C5E;&#x6027;&#x4E0D;&#x518D;&#x5B58;&#x5728;</span></div></pre></td></tr></table></figure>
<h2 id="&#x5BF9;&#x8C61;&#x7684;&#x679A;&#x4E3E;&#x5C5E;&#x6027;"><a href="#&#x5BF9;&#x8C61;&#x7684;&#x679A;&#x4E3E;&#x5C5E;&#x6027;" class="headerlink" title="&#x5BF9;&#x8C61;&#x7684;&#x679A;&#x4E3E;&#x5C5E;&#x6027;"></a>&#x5BF9;&#x8C61;&#x7684;&#x679A;&#x4E3E;&#x5C5E;&#x6027;</h2><p>&#x9664;&#x4E86;&#x68C0;&#x6D4B;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x6211;&#x4EEC;&#x7ECF;&#x5E38;&#x9700;&#x8981;&#x904D;&#x5386;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x901A;&#x5E38;&#x4F7F;&#x7528; for-in &#x904D;&#x5386;</p>
<p>ECMAScript 5 &#x63D0;&#x4F9B;&#x4E86; Object.keys() &#x65B9;&#x6CD5;&#xFF0C;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x7531;&#x5BF9;&#x8C61;&#x4E2D;&#x53EF;&#x679A;&#x4E3E;&#x7684;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#x7684;&#x540D;&#x79F0;&#x7EC4;&#x6210;&#x3002;</p>
<p>ECMASciript 5 &#x63D0;&#x4F9B;&#x7684;&#x53E6;&#x4E00;&#x79CD;&#x679A;&#x4E3E;&#x5C5E;&#x6027;&#x7684;&#x65B9;&#x6CD5;&#x662F; Object.getOwnPropertyNames(),<br>&#x548C; Object.keys() &#x7C7B;&#x4F3C;&#xFF0C;&#x53EA;&#x662F;&#x5B83;&#x8FD4;&#x56DE;&#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x800C;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x53EF;&#x4EE5;&#x679A;&#x4E3E;&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<h3 id="&#x7528;&#x6765;&#x679A;&#x4E3E;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x5DE5;&#x5177;&#x51FD;&#x6570;"><a href="#&#x7528;&#x6765;&#x679A;&#x4E3E;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x5DE5;&#x5177;&#x51FD;&#x6570;" class="headerlink" title="&#x7528;&#x6765;&#x679A;&#x4E3E;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x5DE5;&#x5177;&#x51FD;&#x6570;"></a>&#x7528;&#x6765;&#x679A;&#x4E3E;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x5DE5;&#x5177;&#x51FD;&#x6570;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * [extend description] &#x628A; P &#x4E2D;&#x7684;&#x53EF;&#x679A;&#x4E3E;&#x5C5E;&#x6027;&#x590D;&#x5236;&#x5230; o &#x4E2D;&#xFF0C;</div><div class="line"> * &#x5982;&#x679C;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x8986;&#x76D6; o &#x4E2D;&#x7684;&#x5C5E;&#x6027; </div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @param  {[type]} p [description]</div><div class="line"> * @return {[type]}   [description]</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">extend</span>(<span class="params">o, p</span>) </span>{</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> prop <span class="keyword">in</span> p) {</div><div class="line">    o[prop] = p [prop];</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> o;</div><div class="line">}</div><div class="line"><span class="comment">/**</span></div><div class="line"> * [merge description] &#x628A; P &#x4E2D;&#x7684;&#x53EF;&#x679A;&#x4E3E;&#x5C5E;&#x6027;&#x590D;&#x5236;&#x5230; o &#x4E2D;&#xFF0C;</div><div class="line"> * &#x5982;&#x679C;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;, o &#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x4E0D;&#x53D7;&#x5F71;&#x54CD; </div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @param  {[type]} p [description]</div><div class="line"> * @return {[type]}   [description]</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">merge</span> (<span class="params">o, p</span>) </span>{</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> prop <span class="keyword">in</span> p) {</div><div class="line">    <span class="keyword">if</span> (o.hasOwnProperty[prop]) <span class="keyword">continue</span>;</div><div class="line">    o[prop] = p [prop];</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> o;</div><div class="line">}</div><div class="line"><span class="comment">/**</span></div><div class="line"> * [restrict description] &#x5982;&#x679C; o &#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x6CA1;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x4ECE; o &#x4E2D;&#x5220;&#x9664;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;</div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @param  {[type]} p [description]</div><div class="line"> * @return {[type]}   [description] &#x8FD4;&#x56DE; o </div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">restrict</span> (<span class="params">o, p</span>) </span>{</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> prop <span class="keyword">in</span> p) {</div><div class="line">    <span class="keyword">if</span> (!(prop <span class="keyword">in</span> p)) <span class="keyword">delete</span> o[prop];</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> o;</div><div class="line">}</div><div class="line"><span class="comment">/**</span></div><div class="line"> * [substract description] &#x5982;&#x679C; o &#x4E2D;&#x5B58;&#x5728;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x5220;&#x9664;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;</div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @param  {[type]} p [description]</div><div class="line"> * @return {[type]}   [description]</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">substract</span>(<span class="params">o, p</span>) </span>{</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> prop <span class="keyword">in</span> p) {</div><div class="line">    <span class="keyword">delete</span> o[prop];</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> o;</div><div class="line">}</div><div class="line"><span class="comment">/**</span></div><div class="line"> * [union description] &#x5982;&#x679C;&#x6709;&#x91CD;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x4F7F;&#x7528; p &#x4E2D;&#x7684;&#x5C5E;&#x6027;</div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @param  {[type]} p [description]</div><div class="line"> * @return {[type]}   [description] &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x540C;&#x65F6;&#x62E5;&#x6709; o &#x7684;&#x5C5E;&#x6027;</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">union</span> (<span class="params">o, p</span>) </span>{</div><div class="line">  <span class="keyword">return</span> extend (extend({}, o), p);</div><div class="line">}</div><div class="line"><span class="comment">/**</span></div><div class="line"> * [keys description] &#x8FD4;&#x56DE;&#x7684;&#x6570;&#x7EC4;&#x4E2D;&#x5305;&#x542B;&#x7684;&#x662F; o &#x4E2D;&#x53EF;&#x679A;&#x4E3E;&#x7684;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#x7684;&#x540D;&#x5B57;</div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @return {[type]}   [description] &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">keys</span>(<span class="params">o</span>) </span>{</div><div class="line">  <span class="keyword">if</span> (<span class="keyword">typeof</span> o !== <span class="string">&quot;object&quot;</span>) <span class="keyword">throw</span> <span class="built_in">TypeError</span>();</div><div class="line">  <span class="keyword">var</span> result = [];</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> prop <span class="keyword">in</span> o){</div><div class="line">    <span class="keyword">if</span> (o.hasOwnProperty(prop)) result.push(prop);</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> result;</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x5C5E;&#x6027;-getter-&#x548C;-setter"><a href="#&#x5C5E;&#x6027;-getter-&#x548C;-setter" class="headerlink" title="&#x5C5E;&#x6027; getter &#x548C; setter"></a>&#x5C5E;&#x6027; getter &#x548C; setter</h2><p>&#x5F53;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x67E5;&#x8BE2;&#x5B58;&#x50A8;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x7684;&#x65F6;&#x5019;&#xFF0C;JavaScript &#x8C03;&#x7528; getter &#x65B9;&#x6CD5;(&#x65E0;&#x53C2;&#x6570;)&#xFF0C;&#x5F53;&#x8BBE;&#x7F6E;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x65F6;&#x5019;&#xFF0C;<br>&#x8C03;&#x7528;&#x7684;&#x662F; setter &#x65B9;&#x6CD5;&#x3002;</p>
<h2 id="&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6027;"><a href="#&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6027;" class="headerlink" title="&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6027;"></a>&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6027;</h2><p>&#x5C5E;&#x6027;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x540D;&#x548C;4&#x4E2A;&#x7279;&#x6027;&#xFF1A;</p>
<ul>
<li>value &#x5C5E;&#x6027;&#x503C;</li>
<li>writable &#x53EF;&#x5199;&#x6027;</li>
<li>enumerable &#x53EF;&#x679A;&#x4E3E;&#x6027;</li>
<li>configurable &#x53EF;&#x914D;&#x7F6E;&#x6027;</li>
</ul>
<p>&#x5B58;&#x53D6;&#x5668;&#x5C5E;&#x6027;&#x4E0D;&#x5177;&#x6709;&#x503C; value &#x548C; &#x53EF;&#x5199;&#x6027;</p>
<p>ECMAScript 5 &#x4E2D;&#x5B9A;&#x4E49;&#x4E86;&#x5C5E;&#x6027;&#x63CF;&#x8FF0;&#x7B26; Object.getOwnPropertyDesctiptor() &#x83B7;&#x53D6;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#x7279;&#x5B9A;&#x7684;&#x5C5E;&#x6027;&#xFF0C;<br>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x53EA;&#x80FD;&#x5F97;&#x5230;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6027;&#x3002;</p>
<p>&#x8BA9;&#x65B0;&#x5EFA;&#x7684;&#x5C5E;&#x6027;&#x5177;&#x6709;&#x67D0;&#x79CD;&#x7279;&#x6027;&#xFF0C;&#x9700;&#x8981;&#x8C03;&#x7528; Object.definePeoperty() &#x65B9;&#x6CD5;&#xFF1B;&#x4F20;&#x5165;&#x8981;&#x4FEE;&#x6539;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;<br>&#x8981;&#x521B;&#x5EFA;&#x6216;&#x4FEE;&#x6539;&#x7684;&#x5C5E;&#x6027;&#x7684;&#x540D;&#x79F0;&#x4EE5;&#x53CA;&#x5C5E;&#x6027;&#x63CF;&#x8FF0;&#x7B26;&#x5BF9;&#x8C61;&#xFF1B;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> o = {};  <span class="comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;</span></div><div class="line"><span class="comment">// &#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x4E0D;&#x53EF;&#x679A;&#x4E3E;&#x7684;&#x6570;&#x636E;&#x5C5E;&#x6027; x, &#x5E76;&#x8D4B;&#x503C;&#x4E3A; 1&#xFF1B;</span></div><div class="line"><span class="built_in">Object</span>.defineProperty(o, <span class="string">&quot;x&quot;</span>, {</div><div class="line">  <span class="attr">value</span>: <span class="number">1</span>,</div><div class="line">  <span class="attr">writable</span>: <span class="literal">true</span>,</div><div class="line">  <span class="attr">enumerable</span>: <span class="literal">false</span>,</div><div class="line">  <span class="attr">configurable</span>: <span class="literal">true</span></div><div class="line">});</div><div class="line">o.x;   <span class="comment">// --&gt; 1</span></div><div class="line"><span class="built_in">Object</span>.keys(o); <span class="comment">// --&gt; []</span></div><div class="line"><span class="comment">// &#x5BF9;&#x5C5E;&#x6027; x &#x505A;&#x4FEE;&#x6539;&#x53D8;&#x4E3A;&#x53EA;&#x8BFB;</span></div><div class="line"><span class="built_in">Object</span>.defineProperty(o, <span class="string">&quot;x&quot;</span>, {<span class="attr">writable</span>: <span class="literal">false</span>});</div><div class="line"><span class="comment">// &#x8BD5;&#x56FE;&#x66F4;&#x6539;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x503C;</span></div><div class="line">o.x = <span class="number">2</span>; <span class="comment">// &#x66F4;&#x6539;&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E2D;&#x629B;&#x51FA;&#x5F02;&#x5E38;</span></div><div class="line">o.x;  <span class="comment">// =&gt; 1;</span></div><div class="line"><span class="comment">// &#x5C5E;&#x6027;&#x4F9D;&#x7136;&#x662F;&#x53EF;&#x914D;&#x7F6E;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x5BF9;&#x5B83;&#x8FDB;&#x884C;&#x4FEE;&#x6539;</span></div><div class="line"><span class="built_in">Object</span>.defineProperty(o, <span class="string">&quot;x&quot;</span>, {<span class="attr">value</span>: <span class="number">2</span>});</div><div class="line">o.x; <span class="comment">// =&gt; 2</span></div><div class="line"><span class="comment">// &#x73B0;&#x5728;&#x8BB2; x &#x4ECE;&#x6570;&#x636E;&#x5C5E;&#x6027;&#x4FEE;&#x6539;&#x4E3A;&#x5B58;&#x50A8;&#x5668;&#x5C5E;&#x6027;</span></div><div class="line"><span class="built_in">Object</span>.defineProperty(o, <span class="string">&quot;x&quot;</span>, {</div><div class="line">  <span class="attr">get</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">  }</div><div class="line">});</div><div class="line">o.x; <span class="comment">// =&gt; 0</span></div></pre></td></tr></table></figure>
<p>&#x9700;&#x8981;&#x540C;&#x65F6;&#x4FEE;&#x6539;&#x591A;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x4F7F;&#x7528; Object.defineProperties(),&#x5B83;&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * &#x590D;&#x5236;&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6027;</div><div class="line"> * &#x7ED9; Object.prototype &#x4E0A;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x4E0D;&#x53EF;&#x679A;&#x4E3E;&#x7684;extend() &#x65B9;&#x6CD5;</div><div class="line"> * &#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7EE7;&#x627F;&#x81EA;&#x5B83;&#x7684;&#x8C03;&#x7528;&#x5BF9;&#x8C61;&#xFF0C;&#x5C06;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x7684;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4EE5;&#x4E00;&#x5E45;&#x5B57;</div><div class="line"> * &#x9664;&#x4E86;&#x503C;&#x4E4B;&#x5916;&#x4E5F;&#x8D4B;&#x503C;&#x5C5E;&#x6027;&#x6240;&#x6709;&#x7684;&#x7279;&#x6027;&#xFF0C;&#x9664;&#x975E;&#x5728;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x4E2D;&#x5B58;&#x5728;&#x540C;&#x540D;&#x7684;&#x5C5E;&#x6027;&#x3002;</div><div class="line"> * &#x53C2;&#x6570;&#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#xFF08;&#x5305;&#x62EC;&#x4E0D;&#x53EF;&#x679A;&#x4E3E;&#x7684;&#x5C5E;&#x6027;&#xFF09;&#x4E5F;&#x4F1A;&#x4E00;&#x4E00;&#x590D;&#x5236;</div><div class="line"> */</div><div class="line"><span class="built_in">Object</span>.defineProperty(object.prototype, <span class="string">&quot;extend&quot;</span>, { <span class="comment">// &#x5B9A;&#x4E49; Object.prototype.extend</span></div><div class="line">  writable: <span class="literal">true</span>,</div><div class="line">  <span class="attr">enumerable</span>: <span class="literal">false</span>,  <span class="comment">// &#x5C06;&#x5176;&#x5B9A;&#x4E49;&#x4E3A;&#x4E0D;&#x53EF;&#x679A;&#x4E3E;&#x7684;</span></div><div class="line">  configurable: <span class="literal">true</span>,</div><div class="line">  <span class="attr">value</span>: <span class="function"><span class="keyword">function</span>(<span class="params">o</span>)</span>{</div><div class="line">    <span class="comment">// &#x5F97;&#x5230;&#x6240;&#x6709;&#x7684;&#x81EA;&#x6709;&#x5C5E;&#x6027;&#xFF0C;&#x5305;&#x62EC;&#x4E0D;&#x53EF;&#x679A;&#x4E3E;&#x5C5E;&#x6027;</span></div><div class="line">    <span class="keyword">var</span> names = <span class="built_in">Object</span>.getOwnPropertyNames(o);</div><div class="line">    <span class="comment">// &#x904D;&#x5386;&#x5B83;&#x4EEC;</span></div><div class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; names.length; i++){</div><div class="line">      <span class="comment">// &#x5982;&#x679C;&#x5C5E;&#x6027;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8DF3;&#x8FC7;</span></div><div class="line">      <span class="keyword">if</span> (names[i] <span class="keyword">in</span> <span class="keyword">this</span>) <span class="keyword">continue</span>;</div><div class="line">      <span class="comment">// &#x83B7;&#x53D6; o &#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x63CF;&#x8FF0;&#x7B26;</span></div><div class="line">      <span class="keyword">var</span> desc = <span class="built_in">Object</span>.getOwnPropertyDescriptor(o, names[i])</div><div class="line">      <span class="comment">// &#x7528;&#x5B83;&#x7ED9; this &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;</span></div><div class="line">      <span class="built_in">Object</span>.defineProperty(<span class="keyword">this</span>, names[i], desc)</div><div class="line">    } </div><div class="line">  }</div><div class="line">});</div></pre></td></tr></table></figure>
<h2 id="&#x5BF9;&#x8C61;&#x7684;&#x4E09;&#x4E2A;&#x5C5E;&#x6027;"><a href="#&#x5BF9;&#x8C61;&#x7684;&#x4E09;&#x4E2A;&#x5C5E;&#x6027;" class="headerlink" title="&#x5BF9;&#x8C61;&#x7684;&#x4E09;&#x4E2A;&#x5C5E;&#x6027;"></a>&#x5BF9;&#x8C61;&#x7684;&#x4E09;&#x4E2A;&#x5C5E;&#x6027;</h2><p>&#x6BCF;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x90FD;&#x6709;&#x4E0E;&#x4E4B;&#x76F8;&#x5173;&#x8054;&#x7684;&#x539F;&#x578B; (prototype)&#x3001;&#x7C7B; (class)<br>&#x548C;&#x53EF;&#x6269;&#x5C55;&#x6027; (extensible attribute)&#x3002;</p>
<h3 id="&#x539F;&#x578B;&#x5C5E;&#x6027;"><a href="#&#x539F;&#x578B;&#x5C5E;&#x6027;" class="headerlink" title="&#x539F;&#x578B;&#x5C5E;&#x6027;"></a>&#x539F;&#x578B;&#x5C5E;&#x6027;</h3><p>&#x901A;&#x8FC7;&#x76F4;&#x63A5;&#x91CF;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x4F7F;&#x7528; Object.prototype &#x4F5C;&#x4E3A;&#x5B83;&#x4EEC;&#x7684;&#x539F;&#x578B;&#xFF0C;<br>&#x800C;&#x4F7F;&#x7528; new &#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x4F7F;&#x7528; &#x6784;&#x9020;&#x51FD;&#x6570;&#x7684; prototype &#x5C5E;&#x6027;&#x4F5C;&#x4E3A;&#x5B83;&#x4EEC;&#x7684;&#x539F;&#x578B;&#x3002;<br>&#x800C;&#x901A;&#x8FC7; Object.create() &#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x4F7F;&#x7528;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F5C;&#x4E3A;&#x5B83;&#x4EEC;&#x7684;&#x539F;&#x578B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F; null .</p>
<p>ECMAScript 5 &#x4E2D;&#x5C06;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x5165; Object.getPrototypeOf() &#x65B9;&#x6CD5;&#x4E2D;&#x53EF;&#x4EE5;&#x67E5;&#x8BE2;&#x5B83;&#x7684;&#x539F;&#x578B;&#x3002;</p>
<p>&#x8981;&#x68C0;&#x6D4B;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x662F;&#x53E6;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#xFF08;&#x6216;&#x5904;&#x4E8E;&#x539F;&#x578B;&#x94FE;&#x4E2D;&#xFF09;&#xFF0C;&#x7528; isPrototypeOf() &#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="&#x7C7B;&#x5C5E;&#x6027;"><a href="#&#x7C7B;&#x5C5E;&#x6027;" class="headerlink" title="&#x7C7B;&#x5C5E;&#x6027;"></a>&#x7C7B;&#x5C5E;&#x6027;</h3><p>&#x5BF9;&#x8C61;&#x7684;&#x7C7B;&#x5C5E;&#x6027;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x7528;&#x4EE5;&#x8868;&#x793A;&#x5BF9;&#x8C61;&#x7684;&#x7C7B;&#x578B;&#x4FE1;&#x606F;&#x3002;<br>&#x53EA;&#x6709;&#x4E00;&#x79CD;&#x95F4;&#x63A5;&#x7684;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#xFF0C;&#x5373;toString() &#x65B9;&#x6CD5;&#x3002;<br>&#x9ED8;&#x8BA4;&#x7684; toString() &#x65B9;&#x6CD5;&#x7EE7;&#x627F;&#x81EA; Object.prototype&#xFF0C;&#x8FD4;&#x56DE; <code>[object class]</code> &#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<p>&#x5982;&#x4F55;&#x83B7;&#x5F97;&#x5BF9;&#x8C61;&#x7684;&#x7C7B;&#xFF1F;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * classof() &#x51FD;&#x6570;</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">classof</span>(<span class="params">o</span>)</span>{</div><div class="line">  <span class="keyword">if</span> (o === <span class="literal">null</span> ) <span class="keyword">return</span> <span class="string">&quot;null&quot;</span>;</div><div class="line">  <span class="keyword">if</span> (o === <span class="literal">undefined</span>) <span class="keyword">return</span> <span class="string">&quot;undefined&quot;</span>;</div><div class="line">  <span class="keyword">return</span> <span class="built_in">Object</span>.prototype.toString.call(o).slice(<span class="number">8</span>,<span class="number">-1</span>);</div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x4F20;&#x5165;&#x4EFB;&#x610F;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<h3 id="&#x5BF9;&#x8C61;&#x7684;&#x53EF;&#x6269;&#x5C55;&#x6027;"><a href="#&#x5BF9;&#x8C61;&#x7684;&#x53EF;&#x6269;&#x5C55;&#x6027;" class="headerlink" title="&#x5BF9;&#x8C61;&#x7684;&#x53EF;&#x6269;&#x5C55;&#x6027;"></a>&#x5BF9;&#x8C61;&#x7684;&#x53EF;&#x6269;&#x5C55;&#x6027;</h3><p>ECMAScript 5 &#x7684; Object.preventExtensions() &#x65B9;&#x6CD5;&#x5C06;&#x5BF9;&#x8C61;&#x8F6C;&#x4E3A;&#x4E0D;&#x53EF;&#x6269;&#x5C55;&#x7684;&#xFF0C;<br>Object.seal() &#x8FD8;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4E0D;&#x53EF;&#x914D;&#x7F6E;&#x3002;</p>
<h2 id="&#x5E8F;&#x5217;&#x5316;&#x5BF9;&#x8C61;&#xFF08;JSON-&#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF09;"><a href="#&#x5E8F;&#x5217;&#x5316;&#x5BF9;&#x8C61;&#xFF08;JSON-&#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF09;" class="headerlink" title="&#x5E8F;&#x5217;&#x5316;&#x5BF9;&#x8C61;&#xFF08;JSON &#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF09;"></a>&#x5E8F;&#x5217;&#x5316;&#x5BF9;&#x8C61;&#xFF08;JSON &#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF09;</h2><p>&#x662F;&#x6307;&#x5C06;&#x5BF9;&#x8C61;&#x7684;&#x72B6;&#x6001;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x8FD8;&#x539F;&#x4E3A;&#x5BF9;&#x8C61;&#x3002;</p>
<p>ECMAScript 5 &#x63D0;&#x4F9B;&#x4E86;&#x5185;&#x7F6E;&#x51FD;&#x6570; JSON.stringify() &#x548C; JSON.parse() &#x7528;&#x6765;&#x5E8F;&#x5217;&#x5316;&#x548C;&#x8FD8;&#x539F;JavaScript&#x5BF9;&#x8C61;&#x3002;<br>&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x4F7F;&#x7528; JSON &#x6570;&#x636E;&#x683C;&#x5F0F;&#x3002;</p>
<p>JSON, &#x5373; <code>JavaScript Object Notation</code>&#xFF08; JavaScript &#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;&#xFF09;<br>&#x662F;&#x4EFF;&#x7167;JS&#x4E2D;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x683C;&#x5F0F;&#x53BB;&#x4E66;&#x5199;&#x7684;&#x4E00;&#x4E32;&#x7528;&#x6765;&#x8BB0;&#x5F55;&#x5BF9;&#x8C61;&#x6570;&#x636E;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;<br>&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x6570;&#x636E;&#x4F20;&#x8F93;&#x3002; &#x5373; JSON</p>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x51FD;&#x6570;&#x3001;RegExp&#x3001;Error &#x5BF9;&#x8C61;&#x548C; undefined &#x503C;&#x4E0D;&#x80FD;&#x5E8F;&#x5217;&#x5316;&#x548C;&#x8FD8;&#x539F;</p>
<ul>
<li>JSON &#x8F6C;&#x5B57;&#x7B26;&#x4E32; &#x5E8F;&#x5217;&#x5316; JSON.stringfy();</li>
<li>&#x5B57;&#x7B26;&#x4E32;&#x8F6C; JSON &#x53CD;&#x5E8F;&#x5217;&#x5316; JSON.parse();</li>
</ul>
<h3 id="&#x904D;&#x5386;&#x7684;-JSON-&#x4E24;&#x79CD;&#x65B9;&#x5F0F;"><a href="#&#x904D;&#x5386;&#x7684;-JSON-&#x4E24;&#x79CD;&#x65B9;&#x5F0F;" class="headerlink" title="&#x904D;&#x5386;&#x7684; JSON &#x4E24;&#x79CD;&#x65B9;&#x5F0F;"></a>&#x904D;&#x5386;&#x7684; JSON &#x4E24;&#x79CD;&#x65B9;&#x5F0F;</h3><p>&#x901A;&#x8FC7;for&#x53EF;&#x4EE5;&#x5BF9;&#x96C6;&#x5408;&#x8FDB;&#x884C;&#x6709;&#x5E8F;&#x7684;&#x904D;&#x5386;<br><code>for(var k in json) { &#x8BED;&#x53E5; };</code><br>k&#x53D8;&#x91CF;&#x4EE3;&#x8868;&#x7684;&#x662F;json&#x4E2D;&#x7684;&#x5404;&#x4E2A;&#x5C5E;&#x6027;&#xFF08;key&#xFF09;&#x548C; var i = 0&#x4E2D;&#x7684;i&#x662F;&#x4E00;&#x4E2A;&#x610F;&#x601D;,&#x540D;&#x5B57;&#x4E0D;&#x540C;&#x800C;&#x5DF2;</p>
<h2 id="&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;"><a href="#&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;" class="headerlink" title="&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;"></a>&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;</h2><ul>
<li>toString() &#x65B9;&#x6CD5; </li>
<li>toLocalString() &#x65B9;&#x6CD5; </li>
<li>toJSON() &#x65B9;&#x6CD5;</li>
<li>valueOf() &#x65B9;&#x6CD5;</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将是我最大的鼓励！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/js/" rel="tag">#js</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2014/05/02/07-js-的对象/" rel="next" title="js 的对象">
                <i class="fa fa-chevron-left"></i> js 的对象
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2014/05/11/08-js-的数组/" rel="prev" title="js 的数组">
                js 的数组 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2014/05/02/js-的对象/"
     data-title="js 的对象"
     data-content=""
     data-url="https://hongqinma.github.io/2014/05/02/js-的对象/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2014/05/02/js-的对象/"
           data-title="js 的对象" data-url="https://hongqinma.github.io/2014/05/02/js-的对象/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">29</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#对象的创建"><span class="nav-number">1.</span> <span class="nav-text">对象的创建</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#对象直接量"><span class="nav-number">1.1.</span> <span class="nav-text">对象直接量</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#键值对"><span class="nav-number">1.1.1.</span> <span class="nav-text">键值对</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#例子："><span class="nav-number">1.1.2.</span> <span class="nav-text">例子：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#通过-new-关键字创建对象"><span class="nav-number">2.</span> <span class="nav-text">通过 new 关键字创建对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#原型初识"><span class="nav-number">3.</span> <span class="nav-text">原型初识</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Object-create"><span class="nav-number">4.</span> <span class="nav-text">Object.create()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#属性和方法的查询和设置"><span class="nav-number">5.</span> <span class="nav-text">属性和方法的查询和设置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#属性"><span class="nav-number">5.1.</span> <span class="nav-text">属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方法"><span class="nav-number">5.2.</span> <span class="nav-text">方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#作为关联数组的对象"><span class="nav-number">5.3.</span> <span class="nav-text">作为关联数组的对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#继承"><span class="nav-number">5.4.</span> <span class="nav-text">继承</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#属性访问错误"><span class="nav-number">5.5.</span> <span class="nav-text">属性访问错误</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除属性"><span class="nav-number">6.</span> <span class="nav-text">删除属性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#属性检测"><span class="nav-number">7.</span> <span class="nav-text">属性检测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#对象的枚举属性"><span class="nav-number">8.</span> <span class="nav-text">对象的枚举属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#用来枚举对象属性的工具函数"><span class="nav-number">8.1.</span> <span class="nav-text">用来枚举对象属性的工具函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#属性-getter-和-setter"><span class="nav-number">9.</span> <span class="nav-text">属性 getter 和 setter</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#属性的特性"><span class="nav-number">10.</span> <span class="nav-text">属性的特性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#对象的三个属性"><span class="nav-number">11.</span> <span class="nav-text">对象的三个属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#原型属性"><span class="nav-number">11.1.</span> <span class="nav-text">原型属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#类属性"><span class="nav-number">11.2.</span> <span class="nav-text">类属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#对象的可扩展性"><span class="nav-number">11.3.</span> <span class="nav-text">对象的可扩展性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#序列化对象（JSON-对象表示法）"><span class="nav-number">12.</span> <span class="nav-text">序列化对象（JSON 对象表示法）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#遍历的-JSON-两种方式"><span class="nav-number">12.1.</span> <span class="nav-text">遍历的 JSON 两种方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#对象的方法"><span class="nav-number">13.</span> <span class="nav-text">对象的方法</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
